﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MapLibrary
{
    class SelectionManager<T>
    {

        private PageManager<T> mPageManager;
        private int mSelectionNumber;
        private int mNumberPerPage;
        private List<T> mToTrack;

        public SelectionManager(List<T> toTrack, int numberPerPage)
        {
            mToTrack = toTrack;
            mSelectionNumber = 0;
            mNumberPerPage = numberPerPage;
            mPageManager = new PageManager<T>(toTrack, numberPerPage);
        }

        public T Selection
        {
            get { return mPageManager.CurrentPage[mSelectionNumber]; }
        }

        public int SelectionIndex
        {
            get { return mSelectionNumber; }
        }

        public Page<T> CurrentPage
        {
            get { return mPageManager.CurrentPage; }
        }

        public int CurrentPageNumber
        {
            get { return mPageManager.CurrentPageNumber; }
        }

        public int NumberOfPages
        {
            get { return mPageManager.NumberOfPages; }
        }

        public void MoveSelectionLeft()
        {
            if (mSelectionNumber > 0)
                mSelectionNumber -= 1;
            else
            {
                if (mPageManager.CanFlipLeft)
                {
                    mPageManager.FlipLeft();
                    mSelectionNumber = mNumberPerPage - 1;
                }
            }
        }


        public void MoveSelectionRight()
        {
            if (mSelectionNumber < mPageManager.NumberOfElementsOnCurrentPage - 1)
                mSelectionNumber += 1;
            else
            {
                if (mPageManager.CanFlipRight)
                {
                    mPageManager.FlipRight();
                    mSelectionNumber = 0;
                }
            }
        }
    }
}
